package com.sy.utils;

import com.baidu.aip.contentcensor.AipContentCensor;
import org.json.JSONObject;


public class BaidCensorUtil {
    //设置APPID/AK/SK
    public static final String APP_ID = "23055816";
    public static final String API_KEY = "G0QZ9ywgyzGtnF1ZBbt5H6Yw";
    public static final String SECRET_KEY = "uhjEZ0hbQdDc0lzTWdwxenGQ8lrZjDt8";
    // 初始化一个AipContentCensor
    private static AipContentCensor client;
    static {
        client= new AipContentCensor(APP_ID, API_KEY, SECRET_KEY);
        // 可选：设置网络连接参数
        client.setConnectionTimeoutInMillis(2000);
        client.setSocketTimeoutInMillis(60000);
    }
    //图片审核
    public static boolean consorImg(byte[] data){
        JSONObject res = client.imageCensorUserDefined(data,null);
        if("合规".equals(res.getString("conclusion"))){
            return true;
        }else {
            return false;
        }
    }
    //文本审核
    public static boolean consirText(String msg){
        JSONObject res = client.textCensorUserDefined(msg);
        System.out.println(res);
        if("合规".equals(res.getString("conclusion"))){
            return true;
        }
        return false;
    }
}
